package domain;

import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import domain.user.User;

import Persistent.*;

public class Post {

	XmlPost post;
	
	//Constructors
	public Post()
	{
		ObjectFactory factory = new ObjectFactory();
		post = factory.createXmlPost();
		post.setPostId(0);
		post.setOwner(null);
		post.setSubject("");
		post.setBody("");
	}

	public Post(int postID, User owner,String subject, String body) 
	{
		ObjectFactory factory = new ObjectFactory();
		post = factory.createXmlPost();
		
		post.setPostId(postID);
		post.setOwner(owner.getXmlInstance());
		post.setSubject(subject);
		post.setBody(body + "\n\n" + owner.getSigniture());
	}
	
	public Post(XmlPost post)
	{
		this.post = post;
	}
	
	//Getters
	public long getPostId() {
		return post.getPostId();
	}
	
	public List<XmlPost> getReplies() {
		return post.getReplies();
	}

	public XmlLoggedOnUser getOwner() {
		return post.getOwner();
	}

	public String getSubject() {
		return post.getSubject();
	}
	
	public String getBody() {
		return post.getBody();
	}
	
	//Setters	
	public void setPostId(int postId) {
		post.setPostId(postId);
	}
	
	public void setOwner(XmlLoggedOnUser owner) {
		post.setOwner(owner);
	}

	public void setSubject(String subject) {
		post.setSubject(subject);
	}

	public void setBody(String body) {
		post.setBody(body);
	}
	
	/**Function which add new reply to this post
	 * 
	 * @param post
	 * @return true (as specified by Collection.add(E))
	 */
	public boolean addNewReply(Post reply)
	{
		return this.addNewReply(reply.getXmlInstance());
	}
	
	
	public boolean addNewReply(XmlPost reply)
	{
		return this.post.getReplies().add(reply);
	}
	
	public XmlPost getXmlInstance()
	{
		return this.post;
	}

}
 